package com.UI;


import android.app.ActionBar;
import android.app.Activity;
import android.app.ActionBar.Tab;
import android.app.Fragment;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class MyTabsListener<T extends Fragment> implements ActionBar.TabListener{
	private Fragment mFragment;  
    private final Activity mActivity;  
    private final String mTag;  
    private final Class<T> mClass; 
    
	public MyTabsListener(Activity activity, String tag, Class<T> clz) {
		    mActivity = activity;  
	        mTag = tag;  
	        mClass = clz;  
	        
	     

	}

	@Override
	public void onTabReselected(Tab tab, android.app.FragmentTransaction ft) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void onTabSelected(Tab tab, android.app.FragmentTransaction ft) {
		// TODO Auto-generated method stub
		// Check if the fragment is already initialized  
        if (mFragment == null) {  
            // If not, instantiate and add it to the activity  
            mFragment =  Fragment.instantiate(mActivity, mClass.getName());
            ft.add(android.R.id.content, mFragment, mTag);
            
        } else {  
            // If it exists, simply attach it in order to show it  
            ft.attach(mFragment);  
        }  
	}
	@Override
	public void onTabUnselected(Tab tab, android.app.FragmentTransaction ft) {
		// TODO Auto-generated method stub
		 if (mFragment != null) {  
	            // Detach the fragment, because another one is being attached  
	            ft.detach(mFragment);  
	        }  
	}

	
}
